package com.byq.mm.smartlib.connection;

import java.util.Calendar;


import android.app.AlarmManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;

import com.byq.mm.smartlib.SmartActionConstants;

public class LoginManager {
	Context context;

    PendingIntent sender;

	public LoginManager(Context context) {
		super();
		this.context = context;
		Intent intent = new Intent(SmartActionConstants.RELOGIN);
		String pn = context.getPackageName();
		intent.setPackage(pn);
	     sender = PendingIntent.getBroadcast(context, 0,
	          intent, PendingIntent.FLAG_IMMUTABLE|PendingIntent.FLAG_UPDATE_CURRENT);
	}
    public void sendLogin(){

	      // We want the alarm to go off 30 seconds from now.
	      Calendar calendar = Calendar.getInstance();
	      calendar.setTimeInMillis(System.currentTimeMillis());
	      calendar.add(Calendar.SECOND, 3);

	      // Schedule the alarm!
	      AlarmManager am = (AlarmManager) context.getSystemService(Service.ALARM_SERVICE);
	      am.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), sender);

    }
}
